var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    authenticationStatus:false,//认证状态 false 未认证  true 已认证
    authenticationText: "",//认证文本
    passwordStatus:false,// 提现密码状态 false未设置  true 已设置
    passwordText:"",
    address: "",//区地址
    detailAddress: "",//街道详细地址
    contacts:"",
    telephone:"",
    allAddress:"",
    auditStatusText:""

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //that.onMineInfo();
    console.log("onLoad");
  },

  onMineInfo: function () {
    var that = this;
    wx.request({
      method: "POST",
      url: 'https://www.zaishengwang.com/wx/toHomeUser.do',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        id: app.globalData.userId,
      },
      success: function (res) {
        console.log("111", res.data);
        var userVo = res.data.userVo;
        var contacts;
        that.setData({ userVo: userVo });
        if (res.data.userVo.auditStatus == 1) {
          that.setData({ auditStatusText: "未认证" });
        } else if (res.data.userVo.auditStatus == 2) {
          that.setData({ auditStatusText: "认证失败" });
        } else if (res.data.userVo.auditStatus == 3) {
          that.setData({ auditStatusText: "认证成功" });
        }
        var detailAddress = userVo.province + ' ' + userVo.city + ' ' + userVo.area + ' ' + userVo.address ;
        that.setData({ userVo: userVo, allAddress: detailAddress}); 
        if (detailAddress.length > 16) {
          detailAddress = detailAddress.substring(0, 16) + '...';
        }
        console.log(detailAddress);
        if (res.data.userVo.auditStatus == 3){
           contacts = userVo.cardName;
        }else{
          contacts= userVo.contacts;
        }
        that.setData({ contacts: contacts, telephone: userVo.telephone, detailAddress: detailAddress });

      },
      fail: function (error) {
        console.log(error);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log("onReady");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    // if (that.data.authenticationStatus) {
    //   that.setData({ authenticationText: "已认证" });
    // } else {
    //   that.setData({ authenticationText: "未认证" });
    // }
    if (that.data.passwordStatus) {
      that.setData({ passwordText: "修改" });
    } else {
      that.setData({ passwordText: "未设置" });
    }
    console.log("onShow");
    that.onMineInfo();
  },

  //去认证
  goAuthentication:function(){
    var that = this
    // if (that.data.userVo.auditStatus!= 3){
    // wx.navigateTo({
    //   url:'authentication'
    // })
    // }
    wx.navigateTo({
      url: 'authentication'
    })
  },

  // 选择省市区
  chooseAddress: function (e) {
    var that = this;
    wx.navigateTo({
    //  url: '../mine/mapLocation/mapLocation',
    //  url: '../mine/mapLocation/searchMapLocation/searchMapLocation',
      url: 'modifyAddress?allAddress=' + that.data.allAddress + '&lat=' + that.data.userVo.lat + '&lnt=' + that.data.userVo.lnt,
    })
  },
//更换手机号事件
  modifyPhone:function(){
    wx.navigateTo({
      url: 'modifyPhone',
    })
  },
  //修改联系人
  modifyContacts:function(){
    var that = this;
    if (that.data.userVo.auditStatus != 3) {
    wx.navigateTo({
      url: 'modifyContacts',
    })
    }
  },

  //提现密码
  // goCipher:function(){
  //   var that = this;
  //   if (that.data.userVo.auditStatus == 3) {
  //     wx.navigateTo({
  //       url: 'cipher',
  //     })
  //   }

  // },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})